<?php
IncludeFunction("location");

function listOptionStarHotel($star)
{
    $options="";
	for($i=0;$i<=5;$i++)
	{
		if($i==$star)
		{
			$options.="<option value=$i selected>$i</option>";
		}else
		{
			$options.="<option value=$i>$i</option>";
		}
	}
	return $options;
}

function ListHotelByLocationId($locId=0,$status=-1,$search='')
{
global $dbsql,$language;

    $hotels         = array();
    $sql_where      = " where clanguage='$language' ";
    if($locId>0)
    {
        $sql_where  .= " and iParentId=$locId ";
    }
    if($status>-1)
    {
        $sql_where .= " and iStatus=$status ";
    }
    if(!empty($search))
    {
        $sql_where .= " and cName like '$search%' ";
    }
    //get limit to split page:
    $sql_select     = "select count(iId) as count from tblhotel ".$sql_where;
    $result         = $dbsql->query_fetch($sql_select);
    $count_all      = $result['count'];
    list($limit_st,$limit_le)	=Slit_Page($count_all);

    //load hotels
    $sql_select     = "select * from tblhotel ".$sql_where." order by iOrder limit $limit_st,$limit_le";
    $rs             = $dbsql->query($sql_select);
    $hotels      = $dbsql->fetch_rows_array($rs);
    return $hotels;
}

function ListPhotoHotel()
{
	global $id,$language,$ListContent,$dbsql;
	$ListContent=array();

	$sql_select="SELECT count(iId) as count from tblhotel_photo where iParentId = '$id' ";
	$rs=$dbsql->query($sql_select);
	$result=$dbsql->fetch_array($rs);
	$count_all=$result['count'];
	if($count_all==0)return  $ListContent;

	list($lmstart,$lmlength)=Slit_Page($count_all);

	$sql_select = "SELECT * FROM tblhotel_photo WHERE iParentId = '$id' order by iOrder Asc limit $lmstart,$lmlength";

	$rs=$dbsql->query($sql_select);
	$rows = $dbsql->num_rows($rs);
	while ( $result = $dbsql->fetch_array($rs) )
	{
		$file=basename($result['cImage']);
		$result['cThumb']=str_replace($file,"thumbs/".$file,$result["cImage"]);
		$ListContent[] = $result;
	}
    return $ListContent;
}
?>